﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MockPrjTeam4.Biz;
using MockPrjTeam4.Entity;

namespace MockPrjTeam4.Pages.Views
{
    public partial class PopupTypeofBusiness : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            gvTypeOfBusiness.DataSource = TypeOfBusinessBiz.GetListTypeOfBusiness();
            gvTypeOfBusiness.DataBind();
            
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            int id = (int)gvTypeOfBusiness.SelectedDataKey.Values["BusinessId"];
            TypeOfBusiness typeOfBusiness = TypeOfBusinessBiz.GetTypeOfBusinessById(id);
            StringBuilder script = new StringBuilder();
            script.Append("<script type='text/javascript'>");

            script.AppendFormat("window.opener.document.getElementById('txtTypeOfBusiness').value  = '{0}';",
                typeOfBusiness.BusinessName);
            script.AppendFormat("window.opener.document.getElementById('hdfTypeOfBusinessId').value  = '{0}';",
                typeOfBusiness.BusinessId);
            script.AppendFormat("window.opener.document.getElementById('txtSICCode').value  = '{0}';",
                 typeOfBusiness.SICCode);
            script.Append("this.close();");
            script.Append("</script>");
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "key01", script.ToString(), false);
            //Response.Redirect("AddDepartment.aspx?ID=" + id.ToString());
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtFirstname.Text = "";
            txtSurname.Text = "";
        }

        protected void btnNone_Click(object sender, EventArgs e)
        {
            StringBuilder script = new StringBuilder();
            script.Append("<script type='text/javascript'>");
            script.AppendFormat("window.opener.document.getElementById('txtTypeOfBusiness').value = '{0}';", "");
            script.AppendFormat("this.close();");
            script.Append("</script>");
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "keyNone", script.ToString(), false);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            gvTypeOfBusiness.DataSource = TypeOfBusinessBiz.Search(txtFirstname.Text, txtSurname.Text);
            gvTypeOfBusiness.DataBind();
        }
    }
}